﻿/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1
 *
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations
 * under the License.
 *
 * The Original Code is tyzoh.jp code.
 *
 * The Initial Developer of the Original Code is Kazutaka Kurihara.
 * Portions created by the Initial Developer are Copyright (C) 2007
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *
 * ***** END LICENSE BLOCK ***** */
using System;
using System.Windows.Forms;
using PluginInterface;
using System.Drawing;
using Qurihara;
using Microsoft.Ink;
using Qurihara.QBasic;

namespace KotodamaPlugin.BCDrawingAttributePlugin
{
	/// <summary>
	/// Class1 の概要の説明です。
	/// </summary>
	public class BCDrawingAttributePlugin :IPlugin
	{
		private MenuItem menuDR;

		private MenuItem menuSK;
		private MenuItem menuSR;
		private MenuItem menuSB;
		private MenuItem menuMK;
		private MenuItem menuMR;
		private MenuItem menuMB;
		private MenuItem menuLK;
		private MenuItem menuLR;
		private MenuItem menuLB;
		private MenuItem menuFY;
		private MenuItem menuIP;
		private MenuItem menuLine;
		private MenuItem menuBGB;
		private MenuItem menuSW;
		private MenuItem menuMW;
		private MenuItem menuLW;


        private bool IsLanguage(string twoLetterISOLanguageName)
        {
            return (twoLetterISOLanguageName ==
                System.Threading.Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName);
        }
		public BCDrawingAttributePlugin()
		{

			//menuDR = new MenuItem("ペン設定");
            menuDR = new MenuItem(IsLanguage("en") ? "Pen" : "ペン設定");

			menuSK = new MenuItem();
			menuSK.RadioCheck = true;
			menuSK.Index = 0;
            menuSK.Text = IsLanguage("en") ? "Thin black" : "細めの黒ペン";
			menuSK.Click +=new EventHandler(menu_Click);
			menuSR = new MenuItem();
			menuSR.RadioCheck = true;
			menuSR.Index = 1;
            menuSR.Text = IsLanguage("en") ? "Thin red" : "細めの赤ペン";
			menuSR.Click +=new EventHandler(menu_Click);
			menuSB = new MenuItem();
			menuSB.RadioCheck = true;
			menuSB.Index = 2;
            menuSB.Text = IsLanguage("en") ? "Thin blue" : "細めの青ペン";
			menuSB.Click +=new EventHandler(menu_Click);

			menuMK = new MenuItem();
			menuMK.RadioCheck = true;
			menuMK.Index = 3;
            menuMK.Text = IsLanguage("en") ? "Medium black" : "中くらいの黒ペン";
			menuMK.Click +=new EventHandler(menu_Click);
			menuMR = new MenuItem();
			menuMR.RadioCheck = true;
			menuMR.Index = 4;
            menuMR.Text = IsLanguage("en") ? "Medium red" : "中くらいの赤ペン";
			menuMR.Click +=new EventHandler(menu_Click);
			menuMB = new MenuItem();
			menuMB.RadioCheck = true;
			menuMB.Index = 5;
            menuMB.Text = IsLanguage("en") ? "Medium blue" : "中くらいの青ペン";
			menuMB.Click +=new EventHandler(menu_Click);

			menuLK = new MenuItem();
			menuLK.RadioCheck = true;
			menuLK.Index = 6;
            menuLK.Text = IsLanguage("en") ? "Thick black" : "太い黒ペン";
			menuLK.Click +=new EventHandler(menu_Click);
			menuLR = new MenuItem();
			menuLR.RadioCheck = true;
			menuLR.Index = 7;
            menuLR.Text = IsLanguage("en") ? "Thick red" : "太い赤ペン";
			menuLR.Click +=new EventHandler(menu_Click);
			menuLB = new MenuItem();
			menuLB.RadioCheck = true;
			menuLB.Index = 8;
            menuLB.Text = IsLanguage("en") ? "Thick red" : "太い青ペン";
			menuLB.Click +=new EventHandler(menu_Click);

			menuFY = new MenuItem();
            menuFY.RadioCheck = true;
            menuFY.Index = 9;
            menuFY.Text = IsLanguage("en") ? "Fluor yellow" : "黄色い蛍光ペン";
            menuFY.Click += new EventHandler(menu_Click);
            menuFY.Enabled = false;
            menuFY.Visible = false;

            menuIP = new MenuItem();
            menuIP.Index = 10;
            menuIP.Text = IsLanguage("en") ? "Ignore pen pressure" : "筆圧を無視";
            menuIP.Click += new EventHandler(menu_Click);

			menuLine = new MenuItem();
			menuLine.Index = 10;
			menuLine.Text = "-";
			menuBGB = new MenuItem();
			menuBGB.Index = 11;
            menuBGB.Text = IsLanguage("en") ? "Blackboard mode" : "黒板";
			menuBGB.Click +=new EventHandler(menu_Click);
			menuSW= new MenuItem();
			menuSW.RadioCheck = true;
			menuSW.Index = 12;
            menuSW.Text = IsLanguage("en") ? "Thin white" : "細い白ペン";
			menuSW.Click +=new EventHandler(menu_Click);
			menuMW = new MenuItem();
			menuMW.RadioCheck = true;
			menuMW.Index = 13;
            menuMW.Text = IsLanguage("en") ? "Medium white" : "中くらいの白ペン";
			menuMW.Click +=new EventHandler(menu_Click);
			menuLW = new MenuItem();
			menuLW.RadioCheck = true;
			menuLW.Index = 14;
            menuLW.Text = IsLanguage("en") ? "Thick white" : "太い白ペン";
			menuLW.Click +=new EventHandler(menu_Click);


			menuSR.Checked = true;

			menuDR.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																			  menuSK,
																			  menuSR,
																			  menuSB,
																			  menuMK,
																			  menuMR,
																			  menuMB,
																			  menuLK,
																			  menuLR,
																			  menuLB,
																			  menuFY,
																			  menuIP,
				menuLine,
				menuBGB,
				menuSW,
				menuMW,
				menuLW
			});



		}


		#region IPlugin Members
		
		IPluginHost myPluginHost = null;
		string myPluginName = "DrawingAttribute Plugin";
		string myPluginAuthor = "K.Qurihara";
		string myPluginDescription = "test plugin";
		string myPluginVersion = "1.0.0";
		
        
		void PluginInterface.IPlugin.Dispose()
		{
			// TODO:  Add ctlMain.PluginInterface.IPlugin.Dispose implementation
			Menu.MenuItemCollection mic = (Menu.MenuItemCollection)Host.Kotodama.EnvironmentTable["Base.MenuItems"];
			mic.Remove(menuDR);
			//Host.Kotodama.Form.Menu.MenuItems.Remove(menuDR);
		}

		public string Description
		{
			get
			{
				// TODO:  Add ctlMain.Description getter implementation
				return myPluginDescription;
			}
		}

		public string Author
		{
			get
			{
				// TODO:  Add ctlMain.Author getter implementation
				return myPluginAuthor;
			}
		}

		public IPluginHost Host
		{
			get
			{
				// TODO:  Add ctlMain.Host getter implementation
				return myPluginHost;
			}
			set
			{
				myPluginHost = value;
			}
		}

		public void Initialize()
		{
			// TODO:  Add ctlMain.Initialize implementation
			Menu.MenuItemCollection mic = (Menu.MenuItemCollection)Host.Kotodama.EnvironmentTable["Base.MenuItems"];
			mic.Add(menuDR);
			//Host.Kotodama.Form.Menu.MenuItems.Add(menuDR);
		}

		
		public string Name
		{
			get
			{
				// TODO:  Add ctlMain.Name getter implementation
				return myPluginName;
			}
		}
		

		public string Version
		{
			get
			{
				// TODO:  Add ctlMain.Version getter implementation
				return myPluginVersion;
			}
		}

		#endregion

		private void menu_Click(object sender, EventArgs e)
		{
			InkCollector ic = Host.Kotodama.InkCollector;
			if (sender == menuBGB)
			{
				menuBGB.Checked = !menuBGB.Checked;
				if (menuBGB.Checked)
				{
					Host.Kotodama.Control.BackColor = Color.Black;
				}
				else
				{
					Host.Kotodama.Control.BackColor = Color.White;
				}
			}
			if (sender == menuIP)
			{
				menuIP.Checked = !menuIP.Checked;
			}
			ic.DefaultDrawingAttributes.IgnorePressure = menuIP.Checked;

			menuSK.Checked = false;
			menuSR.Checked = false;
			menuSB.Checked = false;
			menuMK.Checked = false;
			menuMR.Checked = false;
			menuMB.Checked = false;
			menuLK.Checked = false;
			menuLR.Checked = false;
			menuLB.Checked = false;
			menuFY.Checked = false;
			menuSW.Checked = false;
			menuMW.Checked = false;
			menuLW.Checked = false;

			if(sender == menuSK)
			{
				menuSK.Checked = true;
				ic.DefaultDrawingAttributes.PenTip = PenTip.Ball;
				ic.DefaultDrawingAttributes.Width = ViewDependentLength(75);//50;
				ic.DefaultDrawingAttributes.Color = Color.Black;
				ic.DefaultDrawingAttributes.Transparency = 1;
			}	
			else if(sender == menuSR)	
			{
				menuSR.Checked = true;
				ic.DefaultDrawingAttributes.PenTip = PenTip.Ball;
				ic.DefaultDrawingAttributes.Width = ViewDependentLength(75);//50;
				ic.DefaultDrawingAttributes.Color = Color.Red;
				ic.DefaultDrawingAttributes.Transparency = 1;
			}	
			else if(sender == menuSB)
			{
				menuSB.Checked = true;
				ic.DefaultDrawingAttributes.PenTip = PenTip.Ball;
				ic.DefaultDrawingAttributes.Width = ViewDependentLength(75);//50;
				ic.DefaultDrawingAttributes.Color = Color.Blue;
				ic.DefaultDrawingAttributes.Transparency = 1;
			}
			else if(sender == menuMK)
			{
				menuMK.Checked = true;
				ic.DefaultDrawingAttributes.PenTip = PenTip.Ball;
				ic.DefaultDrawingAttributes.Width = ViewDependentLength(125);
				ic.DefaultDrawingAttributes.Color = Color.Black;
				ic.DefaultDrawingAttributes.Transparency = 1;
			}
			else if(sender == menuMR)
			{
				menuMR.Checked = true;
				ic.DefaultDrawingAttributes.PenTip = PenTip.Ball;
				ic.DefaultDrawingAttributes.Width = ViewDependentLength(125);
				ic.DefaultDrawingAttributes.Color = Color.Red;
				ic.DefaultDrawingAttributes.Transparency = 1;
			}
			else if(sender == menuMB)
			{
				menuMB.Checked = true;
				ic.DefaultDrawingAttributes.PenTip = PenTip.Ball;
				ic.DefaultDrawingAttributes.Width = ViewDependentLength(125);
				ic.DefaultDrawingAttributes.Color = Color.Blue;
				ic.DefaultDrawingAttributes.Transparency = 1;
			}	
			else if(sender == menuLK)
			{
				menuLK.Checked =true;
				ic.DefaultDrawingAttributes.PenTip = PenTip.Ball;
				ic.DefaultDrawingAttributes.Width = ViewDependentLength(200);
				ic.DefaultDrawingAttributes.Color = Color.Black;
				ic.DefaultDrawingAttributes.Transparency = 1;
			}
			else if(sender == menuLR)
			{
				menuLR.Checked = true;
				ic.DefaultDrawingAttributes.PenTip = PenTip.Ball;
				ic.DefaultDrawingAttributes.Width = ViewDependentLength(200);
				ic.DefaultDrawingAttributes.Color = Color.Red;
				ic.DefaultDrawingAttributes.Transparency = 1;
			}
			else if(sender == menuLB)
			{
				menuLB.Checked = true;
				ic.DefaultDrawingAttributes.PenTip = PenTip.Ball;
				ic.DefaultDrawingAttributes.Width = ViewDependentLength(200);
				ic.DefaultDrawingAttributes.Color = Color.Blue;
				ic.DefaultDrawingAttributes.Transparency = 1;
			}	
			else if(sender == menuFY)	
			{
				menuFY.Checked = true;
				// ペン先を四角に
				ic.DefaultDrawingAttributes.PenTip = PenTip.Rectangle;
				ic.DefaultDrawingAttributes.Height = ViewDependentLength(1000);
				ic.DefaultDrawingAttributes.Width = ViewDependentLength(500);
				ic.DefaultDrawingAttributes.Color = Color.Yellow;
				// 半透明に
				ic.DefaultDrawingAttributes.Transparency = 80;//40;
				ic.DefaultDrawingAttributes.IgnorePressure = true;

			}
			else if(sender == menuSW)
			{
				menuSW.Checked = true;
				ic.DefaultDrawingAttributes.PenTip = PenTip.Ball;
				ic.DefaultDrawingAttributes.Width = ViewDependentLength(50);
				ic.DefaultDrawingAttributes.Color = Color.White;
				ic.DefaultDrawingAttributes.Transparency = 1;
			}
			else if(sender == menuMW)
			{
				menuMW.Checked = true;
				ic.DefaultDrawingAttributes.PenTip = PenTip.Ball;
				ic.DefaultDrawingAttributes.Width = ViewDependentLength(125);
				ic.DefaultDrawingAttributes.Color = Color.White;
				ic.DefaultDrawingAttributes.Transparency = 1;
			}	
			else if(sender == menuLW)
			{
				menuLW.Checked = true;
				ic.DefaultDrawingAttributes.PenTip = PenTip.Ball;
				ic.DefaultDrawingAttributes.Width = ViewDependentLength(200);
				ic.DefaultDrawingAttributes.Color = Color.White;
				ic.DefaultDrawingAttributes.Transparency = 1;
			}	

		}

		private int ViewDependentLength(int lengthInScreen)
		{
			// この処理はHClassWriteMode.StrokeEventで行うことにしました。
			return lengthInScreen;
			//書くときのサイズがだめ。結果はＶｉｅｗ依存
//			Point [] ps = new Point[2];
//			ps[0] = new Point(0,0);
//			ps[1] = new Point(0,lengthInScreen);//,0);
//			Qurihara.InkView view =
//				Host.Kotodama.Presentation.CurrentSlide.View;
//			view.InkScreenToInkView(ref ps);
//			//view.InkViewToInkScreen(ref ps);
//			return ps[1].Y - ps[0].Y;
		}
	}
}
